require("telescope").setup({
    defaults = require("telescope.themes").get_ivy({
        layout_config = { height = 0.5 },
        path_display = { "filename_first" },
        borderchars = {
            preview = { "─", "│", "─", "│", "┌", "┐", "┘", "└" },
        },
    }),
    pickers = {
        buffers = { sort_lastused = true },
    },
})

pcall(require("telescope").load_extension, "fzf")

local builtin = require("telescope.builtin")

vim.keymap.set("n", "<Leader>b", builtin.buffers, { desc = "List buffers" })
vim.keymap.set("n", "<Leader>/", builtin.current_buffer_fuzzy_find, { desc = "Search in buffer" })

vim.keymap.set("n", "<Leader>ff", builtin.find_files, { desc = "Find files" })
vim.keymap.set("n", "<Leader>fr", builtin.oldfiles, { desc = "Recent files" })
vim.keymap.set("n", "<Leader>fw", builtin.grep_string, { desc = "Find word" })
vim.keymap.set("n", "<Leader>fs", builtin.live_grep, { desc = "Find string" })

vim.keymap.set("n", "<Leader>fg", function()
    builtin.git_files({ cwd = vim.fn.expand("%:h") })
end, { desc = "Git files" })

vim.keymap.set("n", "<Leader>fd", function()
    builtin.diagnostics({ bufnr = 0 })
end, { desc = "Find diagnostics" })

vim.keymap.set("n", "z=", builtin.spell_suggest, { desc = "Spelling suggestions" })
